package com.cwt.sso.genericity;

import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;

import java.util.*;

/**
 * @author chenwt
 * @version V1.0
 * @describe 【方法泛型】
 * @date 2023年08月22日 09:53:10
 */
public class Method {

    private static final Logger logger = LoggerFactory.getLogger(Method.class);

    public static void main(String[] args) {
        List<Map<String, Object>> maps1 = new ArrayList<>();
        List<Map<String, Object>> maps2 = new ArrayList<>();

        Map<String, Object> map = new HashMap<>();
        map.put("11", "12");
        maps1.add(map);

        Object o = mapToObj(maps1);
        logger.info(o.getClass() + " >> " + o);
        Object o1 = mapToObj(maps2);
        logger.info(o1.getClass() + " >> " + o1);
    }

    public static <T> T mapToObj(List<Map<String, Object>> maps) {
        if (CollectionUtils.isEmpty(maps)) {
            return (T) " >>>>>>>>>>>>> ";
        }
        return (T) maps.get(0);
    }

    public <T> void printArray(T[] array) {
        Arrays.stream(array).forEach(element -> logger.info(element.toString()));
    }

}
